package  
{
	import org.flixel.*;
	
	/**
	 * ...
	 * @author Lachlan McInnes
	 */
	public class LightBulbCounter  extends FlxSprite
	{
		public var lightBulbText:FlxText;
		public var pauseText:FlxText;
		private var _counter:int;
		public var lightBulbPic:FlxSprite;
		
		public function LightBulbCounter() 
		{
			lightBulbPic = new FlxSprite(0, 0, ImageFiles.lightbulbBig);
			lightBulbPic.scrollFactor.x = lightBulbPic.scrollFactor.y = 0;
			FlxG.state.add(lightBulbPic);
			
			lightBulbText = new FlxText(0, 10, lightBulbPic.width - 4).setFormat("PowellAntique", 18, 0x778ea1, "center", 0x233e58);
			lightBulbText.scrollFactor.x = lightBulbText.scrollFactor.y = 0;
			
			pauseText = new FlxText(0, 45, 60, "P-Pause").setFormat("PowellAntique", 16, 0x778ea1);
			pauseText.exists = false;
			pauseText.scrollFactor.x = pauseText.scrollFactor.y = 0;
		}
		
		public function get litCount():int
		{
			return _counter;
		}
		
		public function totalLightbulbs():int
		{
			var state:PlayState = FlxG.state as PlayState;
			return state.lightBulbs.countLiving();
		}
		
		public function displayLightBulbCount(lightBulbs:FlxGroup):void
		{
			_counter = 0;
			
			for (var i:int = 0; i < lightBulbs.members.length; i++)
			{
				var index:LightBulb = lightBulbs.members[i] as LightBulb;
				if (index.powered)
				{
					_counter++;
				}
			}
			//lightBulbText.text = _counter + " / ";
			//if (lightBulbs.countLiving() < 0)
			//{
			//	lightBulbText.text += "0";
			//}
			//else
			//{
			//	lightBulbText.text += lightBulbs.countLiving();
			//}
			lightBulbText.text = (lightBulbs.countLiving() - _counter).toString();
		}
		
		public function Update(lightBulbs:FlxGroup):void 
		{
			displayLightBulbCount(lightBulbs);
			
			lightBulbPic.play("on");
			
			super.update();
		}
		
	}
}